package io.renren.modules.basic.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.basic.entity.*;
import io.renren.modules.basic.service.*;
import io.renren.modules.wcs.entity.WeightingPLCEntity;
import io.renren.modules.wcs.service.WeighingPLCService;
import io.renren.modules.work.Utils.ManageConstant;
import io.renren.modules.work.Utils.ManagePublicMethod;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;



/**
 * 
 *
 * @author liguanghao
 * @date 2019-11-13 10:50:42
 */
@Api(description = "子任务")
@RestController
@RequestMapping(value = "generator/mtcctaskruninfodet")
public class MtCcTaskRunInfoDetController {
    @Autowired
    private MtCcTaskRunInfoDetService mtCcTaskRunInfoDetService;
    @Autowired
    private MtCcTaskRunInfoService mtCcTaskRunInfoService;
    @Autowired
    private MtCcWarehousRankService mtCcWarehousRankService;
    @Autowired
    private MtCcWarehousPositionRelatService mtCcWarehousPositionRelatService;
    @Autowired
    private MtCcTaskRunInfoDetLogService mtCcTaskRunInfoDetLogService;
    @Autowired
    private MtCcProductService mtCcProductService;
    @Autowired
    private WeighingPLCService weighingPLCService;
    @Autowired
    private MtCcDeviceCommunLogService mtCcDeviceCommunLogService;

    /**
     * 各个主任务的子任务列表
     */
    @ApiOperation(value = "各个主任务的子任务列表列表",notes="各个主任务的子任务列表列表")
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        List<MtCcTaskRunInfoDetEntity> list = mtCcTaskRunInfoDetService.queryPage(params);

        return R.ok().put("list", list);
    }

    /**
     * 子任务列表
     */
    @ApiOperation(value = "子任务列表列表",notes="子任务列表列表")
    @RequestMapping("/taskruninfodetlist")
    public R taskRunInfoDetList(){
        List<MtCcTaskRunInfoDetEntity> list = mtCcTaskRunInfoDetService.list(new QueryWrapper<MtCcTaskRunInfoDetEntity>().in("status",0,1));

        return R.ok().put("list", list);
    }

    /**
     * 信息
     */
    @ApiOperation(value = "信息",notes="信息")
    @RequestMapping("/info/{id}")
    @RequiresPermissions("generator:mtcctaskruninfodet:info")
    public R info(@PathVariable("id") Integer id){
		MtCcTaskRunInfoDetEntity mtCcTaskRunInfoDet = mtCcTaskRunInfoDetService.getById(id);

        return R.ok().put("mtCcTaskRunInfoDet", mtCcTaskRunInfoDet);
    }

    /**
     * 保存
     */
    @ApiOperation(value = "保存",notes="保存")
    @RequestMapping("/save")
    //@Transactional(rollbackFor = Exception.class)
    public R save(@RequestBody Map<String, Object> params){
        int taskInfoId = Integer.parseInt(String.valueOf(params.get("id")));
        MtCcTaskRunInfoEntity mtCcTaskRunInfoEntity = mtCcTaskRunInfoService.getById(taskInfoId);
        String doorWay=mtCcTaskRunInfoEntity.getTaskCode().substring(1,3);
        String taskCode = ManagePublicMethod.creatOrderCode(ManageConstant.IN_STOCK_ORDER_TYPE, doorWay);
        MtCcTaskRunInfoDetEntity mtCcTaskRunInfoDet=new MtCcTaskRunInfoDetEntity();
        mtCcTaskRunInfoDet.setTaskRunId(mtCcTaskRunInfoEntity.getId());
        mtCcTaskRunInfoDet.setTaskType(mtCcTaskRunInfoEntity.getTaskType());
        mtCcTaskRunInfoDet.setTaskDetCode(taskCode);
        mtCcTaskRunInfoDet.setModel(mtCcTaskRunInfoEntity.getModel());
        mtCcTaskRunInfoDet.setUnit(mtCcTaskRunInfoEntity.getUnit());

        //调用称重
        if (doorWay.equals("A1")){
            doorWay="0001";
        }
        if (doorWay.equals("B1")){
            doorWay="0002";
        }
        if (doorWay.equals("A2")){
            doorWay="0003";
        }
        if (doorWay.equals("A3")){
            doorWay="0004";
        }
        if (doorWay.equals("A4")){
            doorWay="0005";
        }
        Integer warehousingBegin = weighingPLCService.warehousingBegin(mtCcTaskRunInfoEntity.getTaskType(), Integer.parseInt(doorWay));
        try {
            Thread.sleep(400);
        }catch (Exception e){}

        //操作写入日志表mtCcDeviceCommunLog
        MtCcDeviceCommunLogEntity mtCcDeviceCommunLog=new MtCcDeviceCommunLogEntity();
        mtCcDeviceCommunLog.setCreateTime(new Date());
        mtCcDeviceCommunLog.setStatus(0);
        mtCcDeviceCommunLog.setContent("任务编码："+mtCcTaskRunInfoDet.getTaskDetCode()+"启动出入口"+doorWay+"的称重模块");
        mtCcDeviceCommunLogService.save(mtCcDeviceCommunLog);
        System.err.println("========="+warehousingBegin+"======");
        if (warehousingBegin==0){//写入成功，启动称重模块
            WeightingPLCEntity cargoAllMessage =new WeightingPLCEntity();
            if (mtCcTaskRunInfoDet.getTaskType()==0){//入库1，出库2
                cargoAllMessage = weighingPLCService.getCargoAllMessage(Integer.parseInt(doorWay),2);
            }

            if (mtCcTaskRunInfoDet.getTaskType()==1){//入库1，出库2
                cargoAllMessage = weighingPLCService.getCargoAllMessage(Integer.parseInt(doorWay),1);
            }
            //设定额定重量和高度，计算是否超高超重
            Integer status = cargoAllMessage.getStatus();//称重模块称重后返回的状态值
            System.err.println("========="+status+"======");
            if (status==0){//称重成功
                Float weight = cargoAllMessage.getWeight();//重量
                Short height = cargoAllMessage.getHeight();//高度
                //设定额定高度和重量，比对
            }else {
                return R.error("称重模块异常，请排除故障后重试！");
            }
        }else {
            //写入日志表
            MtCcDeviceCommunLogEntity mtCcDeviceCommunLogEntity=new MtCcDeviceCommunLogEntity();
            mtCcDeviceCommunLogEntity.setCreateTime(new Date());
            mtCcDeviceCommunLogEntity.setStatus(0);
            mtCcDeviceCommunLogEntity.setContent("任务编码"+mtCcTaskRunInfoDet.getTaskDetCode()+"称重模块启动失败，IOServer写入异常");
            mtCcDeviceCommunLogService.save(mtCcDeviceCommunLogEntity);
            return R.error("称重模块启动失败，请排除故障后重试！");
        }

        Integer warehousRankId = Integer.parseInt(String.valueOf(params.get("warehousRankId")));
        String productModel="";
        String productNum="";
        String productUnit="";
        if (warehousRankId==0){//库位id为0代表自动分配
            /*if (mtCcTaskRunInfoDet.getModel().substring(0,4).equals("1.01")){//BYH指定高库位
                List<MtCcWarehousRankEntity> list = mtCcWarehousRankService
                        .list(new QueryWrapper<MtCcWarehousRankEntity>()
                                .between("id", 241, 330)
                                .eq("is_occupy", 0)
                                .orderByAsc("id"));
                if (list.size()==0){//长度为0，高库位与备用库位已满
                    return R.error("高库位与备用库位已满,无法自动分配!");
                }else {
                    MtCcWarehousRankEntity mtCcWarehousRankEntity = list.get(0);
                    mtCcWarehousRankEntity.setIsOccupy(1);
                    mtCcWarehousRankService.updateById(mtCcWarehousRankEntity);//更新库位状态为被占用
                    mtCcTaskRunInfoDet.setWarehousRankId(mtCcWarehousRankEntity.getId());
                    mtCcTaskRunInfoDet.setNum(String.valueOf(params.get("num")));
                    mtCcTaskRunInfoDet.setWarehousRankName(mtCcWarehousRankEntity.getAnotherName());

                }
            }else {*/
                List<MtCcWarehousRankEntity> list = mtCcWarehousRankService
                        .list(new QueryWrapper<MtCcWarehousRankEntity>()
                                .eq("is_occupy", 0)
                                .orderByAsc("id"));
                if (list.size()==0){//长度为0，库位已满
                    return R.error("库位已满,无法自动分配!");
                }else {
                    MtCcWarehousRankEntity mtCcWarehousRankEntity = list.get(0);
                    mtCcWarehousRankEntity.setIsOccupy(1);
                    mtCcWarehousRankService.updateById(mtCcWarehousRankEntity);//更新rank表库位状态为被占用
                    mtCcTaskRunInfoDet.setWarehousRankId(mtCcWarehousRankEntity.getId());
                    mtCcTaskRunInfoDet.setNum(String.valueOf(params.get("num")));
                    mtCcTaskRunInfoDet.setWarehousRankName(mtCcWarehousRankEntity.getAnotherName());
                    warehousRankId=mtCcWarehousRankEntity.getId();
                }
            //}
        }else{//库位id不为0，代表手动分配库位
            //查询该库位原本是否被占用
            MtCcWarehousRankEntity mtCcWarehousRankEntity = mtCcWarehousRankService
                    .getOne(new QueryWrapper<MtCcWarehousRankEntity>()
                            .eq("id", warehousRankId));
            if (mtCcWarehousRankEntity.getIsOccupy()==1){//已经被占用
                List<MtCcWarehousPositionRelatEntity> mtCcWarehousPositionRelats = mtCcWarehousPositionRelatService.list(new QueryWrapper<MtCcWarehousPositionRelatEntity>()
                        .eq("warehous_position_id", warehousRankId));//查找出仓库内对应位置存放的货物列表

                for (MtCcWarehousPositionRelatEntity mtCcWarehousPositionRelatEntity:mtCcWarehousPositionRelats){
                    MtCcProductEntity productOnWarehousPositionRelat = mtCcProductService.getById(mtCcWarehousPositionRelatEntity.getProductId());//当前库位上货物的信息
                    productModel=productModel.concat(productOnWarehousPositionRelat.getProductCode()).concat("-");//每种货物编码后加“-”区分
                    productNum=productNum.concat(String.valueOf(productOnWarehousPositionRelat.getQuantity()).concat("-"));//每种货物数量后加“-”区分
                    productUnit=productUnit.concat(productOnWarehousPositionRelat.getUnitName()).concat("-");//每种货物单位名称后加“-”区分
                }
                //新建一条出库子任务
                MtCcTaskRunInfoDetEntity mtCcTaskRunInfoDetEntity=new MtCcTaskRunInfoDetEntity();
                mtCcTaskRunInfoDet.setCreateTime(new Date());
                mtCcTaskRunInfoDet.setWarehousRankId(mtCcWarehousRankEntity.getId());
                mtCcTaskRunInfoDet.setWarehousRankName(mtCcWarehousRankEntity.getAnotherName());
                mtCcTaskRunInfoDet.setTaskRunId(mtCcTaskRunInfoEntity.getId());
                mtCcTaskRunInfoDet.setTaskType(0);
                mtCcTaskRunInfoDet.setStatus(0);
                mtCcTaskRunInfoDet.setTaskDetCode(ManagePublicMethod.creatOrderCode(ManageConstant.OUT_STOCK_ORDER_TYPE,doorWay));
                mtCcTaskRunInfoDet.setModel(productModel);
                mtCcTaskRunInfoDet.setNum(productNum);
                mtCcTaskRunInfoDet.setUnit(productUnit);
                mtCcTaskRunInfoDet.setIsHeight("0");
                mtCcTaskRunInfoDet.setIsWeight("0");
                mtCcTaskRunInfoDetService.save(mtCcTaskRunInfoDet);
                //新建一条出库子任务存日志
                /*MtCcTaskRunInfoDetLogEntity mtCcTaskRunInfoDetLogEntity=new MtCcTaskRunInfoDetLogEntity();
                mtCcTaskRunInfoDetLogEntity.setCreateTime(mtCcTaskRunInfoDet.getCreateTime());
                mtCcTaskRunInfoDetLogEntity.setWarehousRankId(mtCcTaskRunInfoDet.getWarehousRankId());
                mtCcTaskRunInfoDetLogEntity.setWarehousRankName(mtCcTaskRunInfoDet.getWarehousRankName());
                mtCcTaskRunInfoDetLogEntity.setTaskRunId(mtCcTaskRunInfoDet.getTaskRunId());
                mtCcTaskRunInfoDetLogEntity.setTaskType(mtCcTaskRunInfoDet.getTaskType());
                mtCcTaskRunInfoDetLogEntity.setStatus(mtCcTaskRunInfoDet.getStatus());
                mtCcTaskRunInfoDetLogEntity.setTaskDetCode(mtCcTaskRunInfoDet.getTaskDetCode());
                mtCcTaskRunInfoDetLogEntity.setModel(mtCcTaskRunInfoDet.getModel());
                mtCcTaskRunInfoDetLogEntity.setNum(mtCcTaskRunInfoDet.getNum());
                mtCcTaskRunInfoDetLogEntity.setUnit(mtCcTaskRunInfoDet.getUnit());
                mtCcTaskRunInfoDetLogEntity.setIsHeight(mtCcTaskRunInfoDet.getIsHeight());
                mtCcTaskRunInfoDetLogEntity.setIsWeight(mtCcTaskRunInfoDet.getIsWeight());
                mtCcTaskRunInfoDetLogEntity.setRemarks(mtCcTaskRunInfoDet.getRemarks());
                mtCcTaskRunInfoDetLogService.save(mtCcTaskRunInfoDetLogEntity);*/
            }
            mtCcTaskRunInfoDet.setNum(String.valueOf(params.get("num")));
            mtCcTaskRunInfoDet.setWarehousRankId(warehousRankId);
            mtCcTaskRunInfoDet.setWarehousRankName(mtCcWarehousRankService.getById(warehousRankId).getAnotherName());
        }
        mtCcTaskRunInfoDet.setCreateTime(new Date());
        mtCcTaskRunInfoDet.setStatus(0);
        List<MtCcTaskRunInfoDetEntity> mtCcTaskRunInfoDetEntityList = mtCcTaskRunInfoDetService.list(new QueryWrapper<MtCcTaskRunInfoDetEntity>()
                .eq("warehous_rank_id", mtCcTaskRunInfoDet.getWarehousRankId())
                .eq("task_run_id", mtCcTaskRunInfoDet.getTaskRunId()));//同一任务下是否有相同位置的出库任务，若有，本条子任务状态置为"4"(待确认执行)
        if (mtCcTaskRunInfoDetEntityList!=null){
            mtCcTaskRunInfoDet.setModel(productModel.concat(mtCcTaskRunInfoDet.getModel()));
            mtCcTaskRunInfoDet.setNum(productNum.concat(mtCcTaskRunInfoDet.getNum()));
            mtCcTaskRunInfoDet.setUnit(productUnit.concat(mtCcTaskRunInfoDet.getUnit()));
            mtCcTaskRunInfoDet.setStatus(4);
        }
        mtCcTaskRunInfoDetService.save(mtCcTaskRunInfoDet);
        //根据产品code查询产品id、name
        MtCcProductEntity product = mtCcProductService.getOne(new QueryWrapper<MtCcProductEntity>()
                .eq("product_code", mtCcTaskRunInfoDet.getModel()));
        //插入对应库位状态为被占用、货物预入库
        MtCcWarehousPositionRelatEntity mtCcwarehousPositionRelate = new MtCcWarehousPositionRelatEntity();
        mtCcwarehousPositionRelate.setCreateTime(new Date());
        mtCcwarehousPositionRelate.setStatus(3);
        mtCcwarehousPositionRelate.setIsOccupy(1);
        mtCcwarehousPositionRelate.setProductId(product.getId());
        mtCcwarehousPositionRelate.setProductName(product.getProductName());
        mtCcwarehousPositionRelate.setQuantity(Integer.parseInt(String.valueOf(params.get("num"))));
        mtCcwarehousPositionRelate.setWarehousPositionId(warehousRankId);
        mtCcwarehousPositionRelate.setWarehousPositionName(mtCcWarehousRankService.getById(warehousRankId).getAnotherName());
        mtCcWarehousPositionRelatService.save(mtCcwarehousPositionRelate);
        MtCcWarehousRankEntity mtCcWarehousRank = mtCcWarehousRankService.getOne(new QueryWrapper<MtCcWarehousRankEntity>()
                .eq("id", mtCcwarehousPositionRelate.getWarehousPositionId()));
        mtCcWarehousRank.setIsOccupy(1);
        mtCcWarehousRankService.updateById(mtCcWarehousRank);//更新rank表里库位状态
        //存日志
        /*MtCcTaskRunInfoDetLogEntity mtCcTaskRunInfoDetLogEntity=new MtCcTaskRunInfoDetLogEntity();
        mtCcTaskRunInfoDetLogEntity.setCreateTime(mtCcTaskRunInfoDet.getCreateTime());
        mtCcTaskRunInfoDetLogEntity.setWarehousRankId(mtCcTaskRunInfoDet.getWarehousRankId());
        mtCcTaskRunInfoDetLogEntity.setWarehousRankName(mtCcTaskRunInfoDet.getWarehousRankName());
        mtCcTaskRunInfoDetLogEntity.setTaskRunId(mtCcTaskRunInfoDet.getTaskRunId());
        mtCcTaskRunInfoDetLogEntity.setTaskType(mtCcTaskRunInfoDet.getTaskType());
        mtCcTaskRunInfoDetLogEntity.setStatus(mtCcTaskRunInfoDet.getStatus());
        mtCcTaskRunInfoDetLogEntity.setTaskDetCode(mtCcTaskRunInfoDet.getTaskDetCode());
        mtCcTaskRunInfoDetLogEntity.setModel(mtCcTaskRunInfoDet.getModel());
        mtCcTaskRunInfoDetLogEntity.setNum(mtCcTaskRunInfoDet.getNum());
        mtCcTaskRunInfoDetLogEntity.setUnit(mtCcTaskRunInfoDet.getUnit());
        mtCcTaskRunInfoDetLogEntity.setIsHeight(mtCcTaskRunInfoDet.getIsHeight());
        mtCcTaskRunInfoDetLogEntity.setIsWeight(mtCcTaskRunInfoDet.getIsWeight());
        mtCcTaskRunInfoDetLogEntity.setRemarks(mtCcTaskRunInfoDet.getRemarks());
        mtCcTaskRunInfoDetLogService.save(mtCcTaskRunInfoDetLogEntity);*/

        return R.ok();
    }

    /**
     * 修改
     */
    @ApiOperation(value = "修改",notes="修改")
    @RequestMapping("/update")
    @RequiresPermissions("generator:mtcctaskruninfodet:update")
    public R update(@RequestBody MtCcTaskRunInfoDetEntity mtCcTaskRunInfoDet){
		mtCcTaskRunInfoDetService.updateById(mtCcTaskRunInfoDet);
        return R.ok();
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除",notes="删除")
    @RequestMapping("/delete")
    //@Transactional(rollbackFor = Exception.class)
    public R delete(@RequestBody Integer id){
        //根据id查找与之关联（同一对应库位的两条出入库任务）的子任务,一并删除
        MtCcTaskRunInfoDetEntity mtCcTaskRunInfoDetEntity = mtCcTaskRunInfoDetService.getById(id);
        if (mtCcTaskRunInfoDetEntity.getTaskType()==0){//如果删除的是出库子任务，查找与之关联的那一条入库子任务，//一并删除同时更新日志,同时修改库位状态。
            MtCcTaskRunInfoDetEntity inTaskRunInfoDet = mtCcTaskRunInfoDetService.getOne(new QueryWrapper<MtCcTaskRunInfoDetEntity>()
                    .eq("task_run_id", mtCcTaskRunInfoDetEntity.getTaskRunId())
                    .eq("warehous_rank_id", mtCcTaskRunInfoDetEntity.getWarehousRankId())
                    .eq("task_type", 1));
            mtCcTaskRunInfoDetService.removeById(id);//删除出库子任务
            if (inTaskRunInfoDet!=null){
                mtCcTaskRunInfoDetService.removeById(inTaskRunInfoDet.getId());//删除入库子任务
            }

            /*MtCcTaskRunInfoDetLogEntity mtCcTaskRunInfoDetLog = mtCcTaskRunInfoDetLogService
                    .getOne(new QueryWrapper<MtCcTaskRunInfoDetLogEntity>()
                    .eq("task_det_code", mtCcTaskRunInfoDetEntity.getTaskDetCode()));
            MtCcTaskRunInfoDetLogEntity inTaskRunInfoDetLog = mtCcTaskRunInfoDetLogService
                    .getOne(new QueryWrapper<MtCcTaskRunInfoDetLogEntity>()
                            .eq("task_det_code", inTaskRunInfoDet.getTaskDetCode()));
            inTaskRunInfoDetLog.setStatus(3);
            mtCcTaskRunInfoDetLogService.updateById(inTaskRunInfoDetLog);
            mtCcTaskRunInfoDetLog.setStatus(3);
            mtCcTaskRunInfoDetLogService.updateById(mtCcTaskRunInfoDetLog);//更新子任务日志*/
            MtCcWarehousPositionRelatEntity mtCcWarehousPositionRelat = mtCcWarehousPositionRelatService
                    .getOne(new QueryWrapper<MtCcWarehousPositionRelatEntity>()
                            .eq("warehous_position_id", mtCcTaskRunInfoDetEntity.getWarehousRankId()));
            mtCcWarehousPositionRelat.setStatus(3);
            mtCcWarehousPositionRelatService.updateById(mtCcWarehousPositionRelat);//更新库位详情信息
        }else {//如果删除的是入库子任务，查找是否有与之关联的出库子任务
            MtCcTaskRunInfoDetEntity outTaskRunInfoDet = mtCcTaskRunInfoDetService.getOne(new QueryWrapper<MtCcTaskRunInfoDetEntity>()
                    .eq("task_run_id", mtCcTaskRunInfoDetEntity.getTaskRunId())
                    .eq("warehous_rank_id", mtCcTaskRunInfoDetEntity.getWarehousRankId())
                    .eq("task_type", 0));
            if (outTaskRunInfoDet!=null){//如果有，一并删除
                mtCcTaskRunInfoDetService.removeById(id);//删除入库子任务
                mtCcTaskRunInfoDetService.removeById(outTaskRunInfoDet.getId());//删除出库子任务
                /*MtCcTaskRunInfoDetLogEntity mtCcTaskRunInfoDetLog = mtCcTaskRunInfoDetLogService
                        .getOne(new QueryWrapper<MtCcTaskRunInfoDetLogEntity>()
                                .eq("task_det_code", mtCcTaskRunInfoDetEntity.getTaskDetCode()));
                MtCcTaskRunInfoDetLogEntity outTaskRunInfoDetLog = mtCcTaskRunInfoDetLogService
                        .getOne(new QueryWrapper<MtCcTaskRunInfoDetLogEntity>()
                                .eq("task_det_code", outTaskRunInfoDet.getTaskDetCode()));
                outTaskRunInfoDetLog.setStatus(3);
                mtCcTaskRunInfoDetLogService.updateById(outTaskRunInfoDetLog);
                mtCcTaskRunInfoDetLog.setStatus(3);
                mtCcTaskRunInfoDetLogService.updateById(mtCcTaskRunInfoDetLog);//更新子任务日志*/
                MtCcWarehousPositionRelatEntity mtCcWarehousPositionRelat = mtCcWarehousPositionRelatService
                        .getOne(new QueryWrapper<MtCcWarehousPositionRelatEntity>()
                                .eq("warehous_position_id", mtCcTaskRunInfoDetEntity.getWarehousRankId()));
                mtCcWarehousPositionRelat.setStatus(3);
                mtCcWarehousPositionRelatService.updateById(mtCcWarehousPositionRelat);//更新库位详情信息
            }else{//没有与之关联的
                mtCcTaskRunInfoDetService.removeById(id);//删除入库子任务
                /*MtCcTaskRunInfoDetLogEntity mtCcTaskRunInfoDetLog = mtCcTaskRunInfoDetLogService
                        .getOne(new QueryWrapper<MtCcTaskRunInfoDetLogEntity>()
                                .eq("task_det_code", mtCcTaskRunInfoDetEntity.getTaskDetCode()));
                mtCcTaskRunInfoDetLog.setStatus(3);
                mtCcTaskRunInfoDetLogService.updateById(mtCcTaskRunInfoDetLog);//更新子任务日志*/
                MtCcWarehousPositionRelatEntity mtCcWarehousPositionRelat = mtCcWarehousPositionRelatService
                        .getOne(new QueryWrapper<MtCcWarehousPositionRelatEntity>()
                                .eq("warehous_position_id", mtCcTaskRunInfoDetEntity.getWarehousRankId()));
                mtCcWarehousPositionRelatService.removeById(mtCcWarehousPositionRelat);
                mtCcWarehousPositionRelatService.updateById(mtCcWarehousPositionRelat);//更新库位详情信息
                MtCcWarehousRankEntity mtCcWarehousRank = mtCcWarehousRankService
                        .getOne(new QueryWrapper<MtCcWarehousRankEntity>()
                                .eq("id", mtCcTaskRunInfoDetEntity.getWarehousRankId()));
                mtCcWarehousRank.setIsOccupy(0);
                mtCcWarehousRankService.updateById(mtCcWarehousRank);//更新rank表里库位状态
            }
        }

        return R.ok();
    }

}
